<template>
  <div class="box">
    <div class="container">
      <header><span class="button sm">登录</span></header>
      <div class="search-container">
        <div class="img">
          <svg class="icon" aria-hidden="true">
            <use xlink:href="#icon-sousuo1"></use>
          </svg>
          <h2>小白菌搜索</h2>
        </div>
        <div class="input-wrapper">
          <input
            type="text"
            class="input"
            placeholder="搜索你想要的资源.."
            v-model.trim="searchText"
            @keydown.enter="search"
          />
          <i class="iconfont icon-sousuo" @click="search"></i>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from "vue";
import { useRouter } from "vue-router";
const router = useRouter();
const searchText = ref();
function search() {
  if (!searchText.value) {
    return ElMessage({
      message: "请输入关键词后再搜索",
      type: "error",
      showClose: true,
    });
  }
  router.push({
    name: "SearchPage",
    query: {
      q: searchText.value,
    },
  });
}
</script>

<style lang="scss" scoped>
div.box {
  display: flex;
  height: 100vh;
  flex-direction: column;
  background-color: $body-color;
  .container {
    height: 100vh;
    position: relative;
  }
  header {
    display: flex;
    height: 4rem;
    align-items: center;
    span {
      margin-left: auto;
      margin-right: 10px;
    }
  }
  .search-container {
    position: absolute;
    top: 35%;
    left: 50%;
    width: 100%;
    transform: translate(-50%, -50%);
    display: flex;
    gap: 1rem;
    flex-direction: column;
    align-items: center;
    .input-wrapper {
      display: flex;
      justify-content: center;
      width: 100%;
      align-items: center;
      position: relative;
      width: 50%;
      max-width: 500px;
      min-width: 330px;
      .input {
        width: 100%;
      }
      .icon-sousuo {
        position: absolute;
        right: 10px;
        cursor: pointer;
        font-size: 1.5rem;
        transition: 0.3s;
        &:hover {
          transform: rotate(90deg);
          color: $first-color-alt;
        }
      }
    }
    .img {
      display: flex;
      gap: 10px;
      font-size: $h2fz;
      justify-content: center;
      color: $title-color;
      align-items: center;
      .icon {
        width: 3em;
        height: 3em;
      }
      h2 {
        font-weight: 400;
      }
    }
  }
}
</style>
